package com.example.demo4_sport.controller;


import com.example.demo4_sport.entity.QueryInfoByPages;
import com.example.demo4_sport.entity.User;
import com.example.demo4_sport.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {


    @Autowired
    private IUserService userService;

    @GetMapping("/getUserList")
    public String getUserList(QueryInfoByPages queryInfoByPages){
        return userService.getAllUsersByPages(queryInfoByPages);
    }

    @PutMapping("/changeUserState")
    public String changeUserState(@RequestParam("id") Integer id, @RequestParam("state") Boolean state){
        return userService.changeUserState(id,state);
    }

    @PostMapping("/insertUser")
    public String changeUserState(@RequestBody User user){
        return userService.insertUser(user);
    }

    @DeleteMapping("/deleteUser")
    public String deleteUser(@RequestParam("id") Integer id){
        return userService.deleteUserById(id);
    }

    @GetMapping("/getUpdateUser")
    public String getUpdateUser(@RequestParam("id") Integer id){
        return userService.getUpdateUserById(id);
    }

    @PutMapping("/updateUser")
    public String updateUser(User user){
        return userService.updateUserById(user);
    }
}
